<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/ouwiki/db" VERSION="20111028" COMMENT="OU wiki database tables."
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
  <TABLES>
    <TABLE NAME="ouwiki" COMMENT="Main table for OU wiki" NEXT="ouwiki_subwikis">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="course"/>
        <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Course ID" PREVIOUS="id" NEXT="name"/>
        <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Name of wiki" PREVIOUS="course" NEXT="subwikis"/>
        <FIELD NAME="subwikis" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="0=single subwiki (no groups), 1=per-group subwikis, 2=per-user subwikis" PREVIOUS="name" NEXT="timeout"/>
        <FIELD NAME="timeout" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="false" SEQUENCE="false" COMMENT="How long users are allowed to edit, in seconds, before it automatically saves their changes and ends the edit. Null = no timeout." PREVIOUS="subwikis" NEXT="template"/>

        <FIELD NAME="template" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Null for no template, or set to a filename (name only, no path). File will be opened from mod_data/ouwiki and used to initialise the content of all new subwikis." PREVIOUS="timeout" NEXT="intro"/>
        <FIELD NAME="intro" TYPE="text" LENGTH="medium" NOTNULL="false" SEQUENCE="false" COMMENT="Optional non-editable text that displays above the edit field on the start page to describe the purpose of the wiki." PREVIOUS="template" NEXT="editbegin"/>
        <FIELD NAME="editbegin" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Date in seconds since epoch, or null. If set, the wiki is in read-only mode (i.e. even users who have mod/ouwiki:edit cannot actually edit anything) until the specified date." PREVIOUS="intro" NEXT="editend"/>
        <FIELD NAME="editend" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Date in seconds since epoch, or null. If set, the wiki is in read-only mode (i.e. even users who have mod/ouwiki:edit cannot actually edit anything) from the specified date onwards." PREVIOUS="editbegin" NEXT="completionpages"/>
        <FIELD NAME="completionpages" TYPE="int" LENGTH="9" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, wiki should be marked complete once user creates this many new pages of their own." PREVIOUS="editend" NEXT="completionedits"/>
        <FIELD NAME="completionedits" TYPE="int" LENGTH="9" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, wiki should be marked complete once user makes this many edits to the wiki." PREVIOUS="completionpages" NEXT="annotation"/>
        <FIELD NAME="annotation" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If set, wiki will use annotations." PREVIOUS="completionedits" NEXT="introformat"/>
        <FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="annotation" NEXT="enablewordcount"/>
        <FIELD NAME="enablewordcount" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" PREVIOUS="introformat" NEXT="grade"/>

        <FIELD NAME="grade" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="enablewordcount"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for ouwiki"/>
      </KEYS>
      <INDEXES>
        <INDEX NAME="ouwiki_ix_course" UNIQUE="false" FIELDS="course" COMMENT="So we can find all wikis for a course if we want."/>
      </INDEXES>
    </TABLE>

    <TABLE NAME="ouwiki_subwikis" COMMENT="Contains a row for each subwiki. A subwiki is an independent collection of named pages. For example, when a wiki is set to group mode, each group has their own subwiki." PREVIOUS="ouwiki" NEXT="ouwiki_pages">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="wikiid"/>
        <FIELD NAME="wikiid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Wiki that owns this subwiki" PREVIOUS="id" NEXT="groupid"/>
        <FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Null if not a group subwiki. References the group in mdl_groups that this subwiki is for." PREVIOUS="wikiid" NEXT="userid"/>
        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Null if not a user subwiki. References the user in mdl_user that this subwiki is for." PREVIOUS="groupid" NEXT="magic"/>
        <FIELD NAME="magic" TYPE="int" LENGTH="16" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Magic code used to provide a degree of access security for the RSS feeds, i.e. make it impossible to guess the URLs." PREVIOUS="userid"/>
      </FIELDS>
      <KEYS>

        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_subwikis_fk_wikiid"/>
        <KEY NAME="ouwiki_subwikis_fk_wikiid" TYPE="foreign" FIELDS="wikiid" REFTABLE="ouwiki" REFFIELDS="id" PREVIOUS="primary" NEXT="ouwiki_subwikis_fk_groupid"/>
        <KEY NAME="ouwiki_subwikis_fk_groupid" TYPE="foreign" FIELDS="groupid" REFTABLE="groups" REFFIELDS="id" PREVIOUS="ouwiki_subwikis_fk_wikiid" NEXT="ouwiki_subwikis_fk_userid"/>
        <KEY NAME="ouwiki_subwikis_fk_userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="ouwiki_subwikis_fk_groupid"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="ouwiki_pages" COMMENT="Single pages inside a subwiki. If a page has multiple versions, it still has only one entry in this table." PREVIOUS="ouwiki_subwikis" NEXT="ouwiki_versions">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="subwikiid"/>

        <FIELD NAME="subwikiid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="The subwiki that owns this page." PREVIOUS="id" NEXT="title"/>
        <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="Title for the page. All pages must have a title, but the start page for the wiki is set to empty string." PREVIOUS="subwikiid" NEXT="currentversionid"/>
        <FIELD NAME="currentversionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Points to the most recent entry in ouwiki_versions. This is the entry that will appear when viewing the page normally. May be null if there are no versions of the page yet." PREVIOUS="title" NEXT="locked"/>
        <FIELD NAME="locked" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="Allows the page to be locked. Introduced with the Annotations commenting system to allow page locking while editing annotations." PREVIOUS="currentversionid" NEXT="firstversionid"/>
        <FIELD NAME="firstversionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Points to the entry in ouwiki_versions that first related to this page. This is used for participation calculations to help with query load at that point." PREVIOUS="locked"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_pages_fk_currentversionid"/>
        <KEY NAME="ouwiki_pages_fk_currentversionid" TYPE="foreign" FIELDS="currentversionid" REFTABLE="ouwiki_versions" REFFIELDS="id" PREVIOUS="primary" NEXT="subwikiid"/>

        <KEY NAME="subwikiid" TYPE="foreign" FIELDS="subwikiid" REFTABLE="ouwiki_subwikis" REFFIELDS="id" PREVIOUS="ouwiki_pages_fk_currentversionid"/>
      </KEYS>
      <INDEXES>
        <INDEX NAME="subwikiid-title" UNIQUE="true" FIELDS="subwikiid, title"/>
      </INDEXES>
    </TABLE>
    <TABLE NAME="ouwiki_versions" COMMENT="Each row here is a version of the content on a particular subwiki page. Whenever a change is saved, a new version is created." PREVIOUS="ouwiki_pages" NEXT="ouwiki_links">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="pageid"/>

        <FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Page that this is a version of." PREVIOUS="id" NEXT="xhtml"/>
        <FIELD NAME="xhtml" TYPE="text" LENGTH="big" NOTNULL="true" SEQUENCE="false" COMMENT="Contains actual XHTML content of the page. Should be well-formed XML (when placed inside a containing element)." PREVIOUS="pageid" NEXT="timecreated"/>
        <FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Time (seconds since epoch) at which the version was created." PREVIOUS="xhtml" NEXT="userid"/>
        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="User who created this version. May be null if the version was created by the system, such as when the wiki is initialised from a template." PREVIOUS="timecreated" NEXT="changestart"/>
        <FIELD NAME="changestart" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="If a section was edited, set to the starting point (in bytes) of the section within the 'xhtml' field. If the whole page was edited, set to null." PREVIOUS="userid" NEXT="changesize"/>
        <FIELD NAME="changesize" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="If a section was edited, the new size of the section in bytes. Otherwise null." PREVIOUS="changestart" NEXT="changeprevsize"/>
        <FIELD NAME="changeprevsize" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="If a section was edited, the previous size of the section (before editing) in bytes. Otherwise null." PREVIOUS="changesize" NEXT="deletedat"/>
        <FIELD NAME="deletedat" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="timestamp when page version was deleted" PREVIOUS="changeprevsize" NEXT="xhtmlformat"/>
        <FIELD NAME="xhtmlformat" TYPE="int" LENGTH="4" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="deletedat" NEXT="wordcount"/>

        <FIELD NAME="wordcount" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="xhtmlformat" NEXT="previousversionid"/>
        <FIELD NAME="previousversionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Points to the entry in ouwiki_versions of the previous version for the page. This is used for participation calculations to help with query load at that point." PREVIOUS="wordcount"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_versions_fk_pageid"/>
        <KEY NAME="ouwiki_versions_fk_pageid" TYPE="foreign" FIELDS="pageid" REFTABLE="ouwiki_pages" REFFIELDS="id" PREVIOUS="primary" NEXT="ouwiki_versions_fk_userid"/>
        <KEY NAME="ouwiki_versions_fk_userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="ouwiki_versions_fk_pageid"/>
      </KEYS>
    </TABLE>

    <TABLE NAME="ouwiki_links" COMMENT="Keeps record of all wiki-links (links within the wiki that were specified using square brackets, in the topageid or tomissingpage fields) and standard URL links or images (in the tourl field)." PREVIOUS="ouwiki_versions" NEXT="ouwiki_locks">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="fromversionid"/>
        <FIELD NAME="fromversionid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Version that contains this link." PREVIOUS="id" NEXT="topageid"/>
        <FIELD NAME="topageid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Target of the link. Must be specified unless the target doesn't exist yet." PREVIOUS="fromversionid" NEXT="tomissingpage"/>
        <FIELD NAME="tomissingpage" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="If link goes to a page that doesn't exist, includes name of missing page. Should be filled in (set this field to null, set topageid) once page is created." PREVIOUS="topageid" NEXT="tourl"/>
        <FIELD NAME="tourl" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="When page links to a URL that is recorded here." PREVIOUS="tomissingpage"/>
      </FIELDS>
      <KEYS>

        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_links_fk_fromversionid"/>
        <KEY NAME="ouwiki_links_fk_fromversionid" TYPE="foreign" FIELDS="fromversionid" REFTABLE="ouwiki_versions" REFFIELDS="id" PREVIOUS="primary" NEXT="ouwiki_links_fk_topageid"/>
        <KEY NAME="ouwiki_links_fk_topageid" TYPE="foreign" FIELDS="topageid" REFTABLE="ouwiki_pages" REFFIELDS="id" PREVIOUS="ouwiki_links_fk_fromversionid"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="ouwiki_locks" COMMENT="When people are editing a subwiki page or section, that information is stored in this table so that other people cannot edit the same thing at the same time." PREVIOUS="ouwiki_links" NEXT="ouwiki_sections">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="pageid"/>
        <FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Page being edited" PREVIOUS="id" NEXT="userid"/>

        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Moodle user who holds this lock." PREVIOUS="pageid" NEXT="versionid"/>
        <FIELD NAME="versionid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Null if whole page is locked. If a section is locked, this is the version that they started off by editing." PREVIOUS="userid" NEXT="sectionstart"/>
        <FIELD NAME="sectionstart" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Null if whole page is locked. If section is locked, this is the start position in bytes relative to the beginning of the 'xhtml' field in the specified version." PREVIOUS="versionid" NEXT="sectionsize"/>
        <FIELD NAME="sectionsize" TYPE="int" LENGTH="9" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Null if whole page is locked. If section is locked, this is the size of the section being edited in bytes." PREVIOUS="sectionstart" NEXT="lockedat"/>
        <FIELD NAME="lockedat" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Time (seconds since epoch) at which lock was first seen." PREVIOUS="sectionsize" NEXT="expiresat"/>
        <FIELD NAME="expiresat" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Time (seconds since epoch) at which lock expires. Null if there is no expiry. (This is a hard lock that occurs about 1 minute after the user-visible timeout.)" PREVIOUS="lockedat" NEXT="seenat"/>
        <FIELD NAME="seenat" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="Time (seconds since epoch) at which the user's client checked in to confirm they still hold the lock. Locks become invalid a certain time after this, in addition to the fixed expiry time." PREVIOUS="expiresat"/>
      </FIELDS>
      <KEYS>

        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_locks_fk_pageid"/>
        <KEY NAME="ouwiki_locks_fk_pageid" TYPE="foreign" FIELDS="pageid" REFTABLE="ouwiki_pages" REFFIELDS="id" PREVIOUS="primary" NEXT="ouwiki_locks_fk_userid"/>
        <KEY NAME="ouwiki_locks_fk_userid" TYPE="foreign" FIELDS="userid" REFTABLE="user" REFFIELDS="id" PREVIOUS="ouwiki_locks_fk_pageid" NEXT="ouwiki_locks_fk_versionid"/>
        <KEY NAME="ouwiki_locks_fk_versionid" TYPE="foreign" FIELDS="versionid" REFTABLE="ouwiki_versions" REFFIELDS="id" PREVIOUS="ouwiki_locks_fk_userid"/>
      </KEYS>
    </TABLE>
    <TABLE NAME="ouwiki_sections" COMMENT="Stores reference to sections (marked by headings) within pages. Entries in this table are only added when sections are actually used to store something in the database. They may remain after the section itself has been deleted from the current page version." PREVIOUS="ouwiki_locks" NEXT="ouwiki_annotations">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" COMMENT="id of the table, please edit me" NEXT="pageid"/>

        <FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="ID of page that this section is for." PREVIOUS="id" NEXT="xhtmlid"/>
        <FIELD NAME="xhtmlid" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="This is the ID used in XHTML for the section, excluding prefix. For example if the heading is &lt;h2 id=&quot;ouwiki_41_325&quot;&gt; then this value will be 41_325. When storing data for the main part of a page rather than a subsection, this should be set to null." PREVIOUS="pageid" NEXT="title"/>
        <FIELD NAME="title" TYPE="char" LENGTH="255" NOTNULL="false" SEQUENCE="false" COMMENT="Title of section in plain text (no HTML), restricted to a reasonable length. The title is taken from the contents of the heading tag in HTML and is updated when the page is saved. ('Dead' sections retain their title in the database.)" PREVIOUS="xhtmlid"/>
      </FIELDS>
      <KEYS>
        <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="primary key of the table, please edit me" NEXT="ouwiki_sections_fk_pageid"/>
        <KEY NAME="ouwiki_sections_fk_pageid" TYPE="foreign" FIELDS="pageid" REFTABLE="ouwiki_pages" REFFIELDS="id" PREVIOUS="primary"/>
      </KEYS>
    </TABLE>

    <TABLE NAME="ouwiki_annotations" COMMENT="Holds the inline comments for the commenting system called Annotations." PREVIOUS="ouwiki_sections">
      <FIELDS>
        <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" NEXT="pageid"/>
        <FIELD NAME="pageid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="used to get all all annotations on a page" PREVIOUS="id" NEXT="userid"/>
        <FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="who created the annotation" PREVIOUS="pageid" NEXT="timemodified"/>
        <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="false" COMMENT="Time the annotation was created or edited" PREVIOUS="userid" NEXT="content"/>
        <FIELD NAME="content" TYPE="text" LENGTH="medium" NOTNULL="true" SEQUENCE="false" COMMENT="Annotation text, plain text not HTML" PREVIOUS="timemodified"/>
      </FIELDS>
      <KEYS>

        <KEY NAME="primary" TYPE="primary" FIELDS="id"/>
      </KEYS>
    </TABLE>
  </TABLES>
</XMLDB>
